package com.skp.shaphan.timing;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

public class MainTimerAction implements ActionListener {
	private ArrayList<TimerAction> actionList = new ArrayList<TimerAction>();

	@Override
	public void actionPerformed(ActionEvent e) {
		ArrayList<TimerAction> toRemove = new ArrayList<TimerAction>();
		for(TimerAction action : actionList) {
			if(action.isComplete()) {
				toRemove.add(action);
			} else {
				action.performAction();
			}
		}
		for(TimerAction action : toRemove) {
			actionList.remove(action);
			action.setRunning(false);
		}
		Thread.yield();
	}
	
	public void addAction(TimerAction action) {
		actionList.add(action);
		action.setRunning(true);
	}

}
